package com.bruce13;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet
 */
public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public TestServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		PrintWriter out=response.getWriter();
		String userid=request.getParameter("userid");
		// 如果是 get進來的中文, 用下面2行來轉換編碼成為UTF-8 (post不需要這樣,只要setCharacterEncoding("UTF-8") )
		String uid=(String) request.getAttribute("userid");
		uid= new String (uid.getBytes(),"ISO-8859-1");
		// 為了 get中文而加入的轉碼
		
		out.print("HELLO"+
		((userid==null)? request.getAttribute(userid):userid));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
